//油卡充值类型选中后，移除提示
	$(document).ready(function(){
		$("#PetroChina").click(function(){
	    	$("#gastype_prompt").hide();
	    	$('#rtprompt').hide();
	  	});
	  	$("#Sinopec").click(function(){
	    	$("#gastype_prompt").hide();
	    	$('#rtprompt').hide();
	  	});
	  	//返回上一步
		$("#goback").click(function(){
			$("#goback").hide();
	    	$("#gas_card_first").show();
			$("#gas_card_next").hide();
			$("#gas_first_button").show();
			$("#gas_next_button").hide();
	  	});
	  	//监听密码是否正确
		$('#password').bind('input propertychange', function() {  
			getCardPrice_var = 1;
			getCardPrice();
		});  
		$('#recardno').bind('input propertychange', function() {  
			getCardPrice_var = 1;
			getCardPrice();
		}); 
	});
	//中石油
	function PetroChina(){
		$("#PetroChina").addClass("gasselected");
		$("#Sinopec").removeClass("gasselected");
		$("input[name=gastype]").val('cnpc');
	}

	//中石化
	function Sinopec(){
		$("#Sinopec").addClass("gasselected");
		$("#PetroChina").removeClass("gasselected");
		$("input[name=gastype]").val('sinopec');
	}

	function Gascardnext(){
		
		var isCheck = true;
		var gasnumber = $('#gasnumber').val();
		var gasname = $('input[name=gasname]').val();
		var gasphone = $('input[name=gasphone]').val();
		var gastype = $('input[name=gastype]').val();
		var openid = $('#openid').val();
		
		var gasphone = $('#gasphone').val();
		//验证加油卡
		if(gastype=='cnpc'){//中石油 9 16
			if(gasnumber.substr(0,1)!='9'||gasnumber.length!=16){
				layer.msg("卡号有误,中石油卡号以9开头，16位.");
				isCheck = false;
				return false;
			}
		}
		if(gastype=='sinopec'){//中石化 100011 19
			if(gasnumber.substr(0,6)!='100011'||gasnumber.length!=19){
				layer.msg("卡号有误,中石油卡号以100011开头，19位.");
				isCheck = false;
				return false;
			}
		}
		if(gasnumber==''){
			$("#gasnumber_prompt").show();
			isCheck = false;
			return false;
		}
		//检测姓名
		var pattern = /^[\u4E00-\u9FA5]{1,6}$/;
		if(gasname==''||!pattern.test(gasname)||gasname.length>20){
			$("#gasname_prompt").show();
			isCheck = false;
			return false;
		}
		//检测手机号
		var myreg = /^(((13[0-9]{1})|(14[0-9]{1})|(17[0]{1})|(15[0-3]{1})|(15[5-9]{1})|(18[0-9]{1}))+\d{8})$/;         
	    if(gasphone == ''||gasphone.length !=11||!myreg.test(gasphone)){  
	        $("#gasphone_prompt").show();
			isCheck = false;
			return false;
	    }
		if(gastype==''){
			$("#gastype_prompt").show();
			isCheck = false;
			return false;
		}
		
		if(isCheck==true){
			$("#gas_first_button").val('加载中...');
			$("#gas_first_button").attr("disabled","disabled");
			$("#gas_first_button").css("background","#666");
			$.ajax({
	        	url:"/recharge/oil/get",
	            type:'post',
	            dataType:'json',
	            data:{"gasnumber":gasnumber,"gasname":gasname,"gastype":gastype,"openid":openid,"gasphone":gasphone},
	            success:function(res)
	            {
	                if(res.code==1){
	                	$("#goback").show();
						$("#gas_card_first").hide();
						$("#gas_card_next").show();
						$("#gas_first_button").hide();
						$("#gas_next_button").show();
						$("#gas_first_button").val('下一步').removeAttr("disabled");
						$("#gas_first_button").css("background","#09BB07");
	                }else{
	                	$("#rtprompt").html(res.msg);
	                	$("#rtprompt").show();
	                	$("#gas_first_button").val('充值');
	                	
	                	$("#gas_first_button").css("background","#666");
	                }
	                //location.href = "";
	            }
	        });
		}
        return false;
	}
	//验证充值卡是否存在
	var getCardPrice_var = 0;
	function getCardPrice(){
	
		var reCardNo=$('#recardno').val();
		var password1 = $('#password').val();
		//alert(reCardNo+" "+password1);
		//alert(reCardNo.length+' '+password1.length);
		if( getCardPrice_var == 1 && reCardNo.length == 16 && password1.length == 8){
		
			//alert("输出完成");
			$.ajax({
	        	url:"/recharge/findcardinfo",
	            type:'post',
	            dataType:'json',
	            data:{'recardno':reCardNo,'password':password1},
	            success:function(res)
	            {
	            	getCardPrice_var = 0;
	                if(res.code==1){
	                	$("#recardno_prompt").text('该卡面额为'+res.data+'元');
	                	$("#gas_next_button").css("background","#09BB07");
	                	$("#gas_next_button").removeAttr("disabled","disabled");
	                }else{  //油卡已消费/不能充值
	                	$("#recardno_prompt").text(res.msg);
	                	$("#gas_next_button").css("background","#666");
	                	$("#gas_next_button").attr("disabled","disabled");
	                }
	                $("#recardno_prompt").show();
	            }
	        });
		}
		
		/* //ajax返回 状态 充值卡面额 根据状态判断提示内容
		  */
        return false;
	} 
	//充值
	var ii=0;
	function Gasrecharge(){
		var gasnumber1 = $('#gasnumber').val();
		ii == 1;
		var data=1;
		layer.confirm('你要充值的油卡是'+'<h2>'+addCommas(gasnumber1)+'</h2>', { title:'充油提示',area: ['90%', '200px']}, function(index){
		  
		  layer.close(index);
		  $("#gas_next_button").val('充值中...');
			$("#gas_next_button").attr("disabled","disabled");
			var isCheck = true;
			var reCardNo=$('#recardno').val();
			var password = $('#password').val();
			if(reCardNo==''){
				
				$("#recardno_prompt").show();
				isCheck = false;
				return false;
			}
			if(password==''){
				$("#password_prompt").show();
				isCheck = false;
				return false;
			}
			
			
			var data = $("#recard_form").serializeArray();
			if(isCheck==true){
				
				var success = 0;
				$.ajax({
		        	url:"/recharge/oil/card",
		            type:'post',
		            dataType:'json',
		            data:data,
		            success:function(res)
		            {
		            	//debugger;
		                if(res.code==0){
		                	$("#recardno_prompt").html(res.msg);
		                	$("#recardno_prompt").show();
		                	$("#gas_next_button").val('充值失败');
		                }else if(res.code==2){
		                	//$("#recardno_prompt").html(res.msg);
		                	$("#recardno_prompt").show();
		                	$("#gas_next_button").val('充值失败');
		                	
		                	layer.open({
		                		  title: '提示'
		                		  ,content: res.msg
		                		});  
		                }else if(res.code==1){
		                	//alert(res.msg)
			                //location.href = res.data; 
		                	layer.msg(res.msg, {
								  icon: 1,
								  time: 5000 //2秒关闭（如果不配置，默认是3秒）
								}, function(){
								  //do something
								  $("#gas_next_button").val('充值完成');
									location.href="/recharge/oil/card/result?orderNo="+res.data;
								});   
		                	//success = 1;
		                	
		                }else if(res.code==-1){
		                	$("#recardno_prompt").html(res.msg);
		                	$("#recardno_prompt").show();
		                	$("#gas_next_button").val('充值').removeAttr("disabled");
		                }else{
		                	$("#recardno_prompt").html(res.msg);
		                	$("#recardno_prompt").show();
		                	$("#gas_next_button").val('充值失败');
		                }
		            }
		        });
				
				
			}
		}); 
		
        return false;
	}
	function addCommas(nStr){
		var value=nStr.replace(/\s/g,'').replace(/(\d{4})(?=\d)/g,"$1 ");
		return value;
	}